﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;
using System.IO;

public partial class Secretaria_bol : System.Web.UI.Page
{
    static Zoom zm = new Zoom();
    Boolean bforceExecute = false;
    DataTable dtNotaSig;
    protected void Page_Load(object sender, EventArgs e)
    {
        //obtengo el significado de las nota
        dtNotaSig = Colegio.Tabla("select numero, letra from tiponotas where idioma = 1");

        if (!IsPostBack)
        {
            HtmlInputText txtZoom = (HtmlInputText)Page.FindControl("zoom");
            txtZoom.Value = zm.GetZoomFromUsuario(biFactory.User().IdUsuario);
        
        }
        RenderGrid();
    
       // Response.Write(HttpContext.Current.Request.Form["Message"].ToString());
        

    }
    
    private void RenderGrid()
    {
        if (Request["r"].Length > 0 && Request["c"].Length > 0)
        {
            XmlDataAlumnos ds = new XmlDataAlumnos();
            DataView dvConce = new DataView(ds.getConceptual(Int32.Parse( Request["c"]), Int32.Parse( Request["r"])));

            if (cboOrden.SelectedValue == "0")
                {
                dvConce.Sort = "Rendimiento desc, Actitud desc";
                }
                else {
                    dvConce.Sort = "Alumno";        
               }
            
            
            GridView1.DataSource = dvConce;
            GridView1.DataBind();

            try
            {
                SchoolsBI.ConceptoReuniones cp = SchoolsBI.ConceptoReuniones.Buscar("id=" + Request["r"]);
                Curso c = Curso.Buscar("IdCurso=" + Request["c"]);
                lblCurso.Text = "Curso :" + c.CursoDescrip + " " + cp.Detalle;
            }
            catch (Exception e) {
                lblCurso.Visible = false;
            }
 
        }


    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        HtmlInputText txtZoom = (HtmlInputText)Page.FindControl("zoom");
        zm.Save(biFactory.User().IdUsuario, txtZoom.Value);
        txtZoom.Style["Color"] = "red";
        
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        //en el header
        if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.Header)
        {
            int cols = e.Row.Cells.Count;
            
            
            e.Row.Cells[0].Style["width"] = "300px";

            for (int iCol = 1; iCol < 4; iCol++)
            {
                e.Row.Cells[iCol].Style["writing-mode"] = "tb-rl";
                e.Row.Cells[iCol].Style["filter"] = "flipv fliph";
                e.Row.Cells[iCol].Style["width"] = "50px";
            }

            for (int iCol = 4; iCol < e.Row.Cells.Count - 2; iCol++)
            {
                e.Row.Cells[iCol].Text = e.Row.Cells[iCol].Text.Substring(0, e.Row.Cells[iCol].Text.Length - 1);
                e.Row.Cells[iCol].ColumnSpan = 2;
                e.Row.Cells[iCol].Style["writing-mode"] = "tb-rl";
                e.Row.Cells[iCol].Style["filter"] = "flipv fliph";
                e.Row.Cells[iCol].Style["width"] = "50px";
                e.Row.Cells.Remove(e.Row.Cells[iCol + 1]);

            }

            e.Row.Cells[e.Row.Cells.Count - 2].Style["writing-mode"] = "tb-rl";
            e.Row.Cells[e.Row.Cells.Count - 2].Style["filter"] = "flipv fliph";
            e.Row.Cells[e.Row.Cells.Count - 2].Style["width"] = "50px";
            e.Row.Cells[e.Row.Cells.Count - 2].Text = "Rendimiento Estimado";
            e.Row.Cells[e.Row.Cells.Count - 1].Style["writing-mode"] = "tb-rl";
            e.Row.Cells[e.Row.Cells.Count - 1].Style["filter"] = "flipv fliph";
            e.Row.Cells[e.Row.Cells.Count - 1].Style["width"] = "50px";
            e.Row.Cells[e.Row.Cells.Count - 1].Text = "Actitud estimada";

        }
        //el los rows
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            e.Row.Cells[1].CssClass = "tdAdvertencia";
            e.Row.Cells[2].CssClass = "tdAmarillas";
            e.Row.Cells[3].CssClass = "tdInasistencias";
            for (int iCol = 4; iCol < e.Row.Cells.Count-2; iCol+=2)
            {
                e.Row.Cells[iCol].CssClass  = "tdcol" ;
            }
            
            
            for (int iCol = 4; iCol < e.Row.Cells.Count; iCol++)
            {
                Decimal iValue;


                if (Decimal.TryParse(e.Row.Cells[iCol].Text, out iValue))
                {

                    e.Row.Cells[iCol].CssClass += " nc" + (int)iValue;

                    if ((int)iValue > 0)
                    {
                        DataRow[] rr = dtNotaSig.Select("Numero = " + ((decimal)iValue).ToString());
                        if (rr.Length > 0)
                        {
                            e.Row.Cells[iCol].Text = rr[0]["Letra"].ToString();
                        }
                    }
                    else { e.Row.Cells[iCol].Text = "A"; }

                }
            }

            e.Row.Cells[e.Row.Cells.Count - 2].CssClass += " tdTot1";
            e.Row.Cells[e.Row.Cells.Count - 1].CssClass += " tdTot2";
        }
    }
}
